Adafruit Fingerprint Library: Adafruit_Fingerprint.h Source File

Adafruit Fingerprint Library

Adafruit_Fingerprint.h
1 #ifndef ADAFRUIT_FINGERPRINT_H
2 #define ADAFRUIT_FINGERPRINT_H
3
4 /***************************************************
5 This is a library for our optical Fingerprint sensor
6
7 Designed specifically to work with the Adafruit Fingerprint sensor
8 ----> http://www.adafruit.com/products/751
9
10 These displays use TTL Serial to communicate, 2 pins are required to
11 interface
12 Adafruit invests time and resources providing this open source code,
13 please support Adafruit and open-source hardware by purchasing
14 products from Adafruit!
15
16 Written by Limor Fried/Ladyada for Adafruit Industries.
17 BSD license, all text above must be included in any redistribution
18 ****************************************************/
19
20 #include "Arduino.h"
21 #if defined(__AVR__) || defined(ESP8266)
22 #include <SoftwareSerial.h>
23 #endif
24
25 #define FINGERPRINT_OK 0x00
26 #define FINGERPRINT_PACKETRECIEVEERR 0x01
27 #define FINGERPRINT_NOFINGER 0x02
28 #define FINGERPRINT_IMAGEFAIL 0x03
29 #define FINGERPRINT_IMAGEMESS 0x06
30 #define FINGERPRINT_FEATUREFAIL 0x07
31 #define FINGERPRINT_NOMATCH 0x08
32 #define FINGERPRINT_NOTFOUND 0x09
33 #define FINGERPRINT_ENROLLMISMATCH 0x0A
34 #define FINGERPRINT_BADLOCATION 0x0B
35 #define FINGERPRINT_DBRANGEFAIL 0x0C
36 #define FINGERPRINT_UPLOADFEATUREFAIL 0x0D
37 #define FINGERPRINT_PACKETRESPONSEFAIL 0x0E
38 #define FINGERPRINT_UPLOADFAIL 0x0F
39 #define FINGERPRINT_DELETEFAIL 0x10
40 #define FINGERPRINT_DBCLEARFAIL 0x11
41 #define FINGERPRINT_PASSFAIL 0x13
42 #define FINGERPRINT_INVALIDIMAGE 0x15
43 #define FINGERPRINT_FLASHERR 0x18
44 #define FINGERPRINT_INVALIDREG 0x1A
45 #define FINGERPRINT_ADDRCODE 0x20
46 #define FINGERPRINT_PASSVERIFY 0x21
47
48 #define FINGERPRINT_STARTCODE 0xEF01
49
50 #define FINGERPRINT_COMMANDPACKET 0x1
51 #define FINGERPRINT_DATAPACKET 0x2
52 #define FINGERPRINT_ACKPACKET 0x7
53 #define FINGERPRINT_ENDDATAPACKET 0x8
54
55 #define FINGERPRINT_TIMEOUT 0xFF
56 #define FINGERPRINT_BADPACKET 0xFE
57
58 #define FINGERPRINT_GETIMAGE 0x01
59 #define FINGERPRINT_IMAGE2TZ 0x02
60 #define FINGERPRINT_REGMODEL 0x05
61 #define FINGERPRINT_STORE 0x06
62 #define FINGERPRINT_LOAD 0x07
63 #define FINGERPRINT_UPLOAD 0x08
64 #define FINGERPRINT_DELETE 0x0C
65 #define FINGERPRINT_EMPTY 0x0D
66 #define FINGERPRINT_VERIFYPASSWORD 0x13
67 #define FINGERPRINT_HISPEEDSEARCH 0x1B
68 #define FINGERPRINT_TEMPLATECOUNT 0x1D
69
70 //#define FINGERPRINT_DEBUG
71
72 #define DEFAULTTIMEOUT 5000 // milliseconds
73
74 struct Adafruit_Fingerprint_Packet {
75 Adafruit_Fingerprint_Packet(uint8_t type, uint16_t length, uint8_t * data) {
76 this->start_code = FINGERPRINT_STARTCODE;
77 this->type = type;
78 this->length = length;
79 address[0] = 0xFF; address[1] = 0xFF;
80 address[2] = 0xFF; address[3] = 0xFF;
81 if(length<64)
82 memcpy(this->data, data, length);
83 else
84 memcpy(this->data, data, 64);
85 }
86 uint16_t start_code;
87 uint8_t address[4];
88 uint8_t type;
89 uint16_t length;
90 uint8_t data[64];
91 };
92
93 class Adafruit_Fingerprint {
94 public:
95 #if defined(__AVR__) || defined(ESP8266)
96 Adafruit_Fingerprint(SoftwareSerial *);
97 #endif
98 Adafruit_Fingerprint(HardwareSerial *);
99
100 void begin(uint16_t baud);
101
102 boolean verifyPassword(void);
103 uint8_t getImage(void);
104 uint8_t image2Tz(uint8_t slot = 1);
105 uint8_t createModel(void);
106
107 uint8_t emptyDatabase(void);
108 uint8_t storeModel(uint16_t id);
109 uint8_t loadModel(uint16_t id);
110 uint8_t getModel(void);
111 uint8_t deleteModel(uint16_t id);
112 uint8_t fingerFastSearch(void);
113 uint8_t getTemplateCount(void);
114 void writeStructuredPacket(const Adafruit_Fingerprint_Packet & p);
115 uint8_t getStructuredPacket(Adafruit_Fingerprint_Packet * p, uint16_t timeout=DEFAULTTIMEOUT);
116
118 uint16_t fingerID;
120 uint16_t confidence;
122 uint16_t templateCount;
123
124 private:
125 uint32_t thePassword;
126 uint32_t theAddress;
127 uint8_t recvPacket[20];
128
129 Stream *mySerial;
130 #if defined(__AVR__) || defined(ESP8266)
131 SoftwareSerial *swSerial;
132 #endif
133 HardwareSerial *hwSerial;
134 };
135
136 #endif
Adafruit_Fingerprint
Definition: Adafruit_Fingerprint.h:93
Adafruit_Fingerprint::confidence
uint16_t confidence
The confidence of the fingerFastSearch() match, higher numbers are more confidents.
Definition: Adafruit_Fingerprint.h:120
Adafruit_Fingerprint::fingerID
uint16_t fingerID
The matching location that is set by fingerFastSearch()
Definition: Adafruit_Fingerprint.h:118
Adafruit_Fingerprint::templateCount
uint16_t templateCount
The number of stored templates in the sensor, set by getTemplateCount()
Definition: Adafruit_Fingerprint.h:122
Adafruit_Fingerprint_Packet
Definition: Adafruit_Fingerprint.h:74